package com.paw.ruoyi.admin.common.dto;

import java.io.Serializable;
import java.util.Date;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 分页请求类
 * @author lvzihai
 * @date 2022/1/19
 **/

@Data
public class PageRequestDTO implements Serializable {

  /** 当前记录起始索引 */
  private Integer pageNum;

  /** 每页显示记录数 */
  private Integer pageSize;

  /** 排序列 */
  private String orderByColumn;

  /** 排序的方向desc或者asc */
  private String isAsc = "asc";

  @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN)
  @JsonFormat(pattern = DatePattern.NORM_DATE_PATTERN)
  private Date beginDate;

  @DateTimeFormat(pattern = DatePattern.NORM_DATE_PATTERN)
  @JsonFormat(pattern = DatePattern.NORM_DATE_PATTERN)
  private Date endDate;


  public PageRequestDTO () {
  }

  public PageRequestDTO (Integer pageNum, Integer pageSize) {
    this.pageNum = pageNum;
    this.pageSize = pageSize;
  }

  public Date getBeginDateTime(){
    if(beginDate==null){
      return null;
    }
    return DateUtil.beginOfDay(beginDate);
  }

  public Date getEndDateTime(){
    if(endDate==null){
      return null;
    }
    return DateUtil.endOfDay(endDate);
  }



}
